from appium import webdriver

import time

from appium.webdriver.common.touch_action import TouchAction
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait

desired_caps = dict()

# 设置中文可输入
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True
# 配置 appium
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '5.1'
desired_caps['deviceName'] = '111'
# 通话记录页面
# desired_caps['appPackage'] = 'com.android.dialer'
# desired_caps['appActivity'] = '.DialtactsActivity'
# 开发者选项页面
desired_caps['appPackage'] = 'com.android.settings'
desired_caps['appActivity'] = '.Settings$DevelopmentSettingsActivity'
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

# 全局等待5s
driver.implicitly_wait(5)

# 1》获取手机屏幕大小
size = driver.get_window_size()  # {'width': 600, 'height': 1024}
# 设置好起始位置start_x,start_y,结束位置end_x,end_y。
# 滑动距离end_x-start_x，end_y-start_y
# start_x = size['width'] * 0.9
# start_y = size['height'] * 0.5
#
# end_x = size['width'] * 0.1
# end_y = size['height'] * 0.5

# .swipe是以为位置到另一个位置
# 向右滑动2次，y轴不变，x轴越来越小
# driver.swipe(size['width'] * 0.9, size['height'] * 0.5, size['width'] * 0.1, size['height'] * 0.5, 500)
# driver.swipe(size['width'] * 0.9, size['height'] * 0.5, size['width'] * 0.1, size['height'] * 0.5, 500)
# # 向左滑动2次，y轴不变，x轴越来越大
# driver.swipe(size['width'] * 0.1, size['height'] * 0.5, size['width'] * 0.9, size['height'] * 0.5, 500)
# driver.swipe(size['width'] * 0.1, size['height'] * 0.5, size['width'] * 0.9, size['height'] * 0.5, 500)

# 向下滑动1次，x轴不变，y轴越来越小
driver.swipe(size['width'] * 0.5, size['height'] * 0.9, size['width'] * 0.5, size['height'] * 0.1)
# 向上滑动1次，x轴不变，y轴越来越大
time.sleep(1)
driver.swipe(size['width'] * 0.5, size['height'] * 0.2, size['width'] * 0.5, size['height'] * 0.9)
time.sleep(3)

driver.quit()
